home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / nwt2.exe / SERVINFO.FRM < prev   
Text File  |  1993-08-10  |  10KB  |  324 lines

  1. VERSION 2.00
  2. Begin Form ServerInfoForm 
  3.    Caption         =   "User Information"
  4.    ClientHeight    =   4335
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   6390
  8.    Height          =   4740
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4335
  12.    ScaleWidth      =   6390
  13.    Top             =   1140
  14.    Width           =   6510
  15.    Begin CommandButton DoneButton 
  16.       Caption         =   "&Done"
  17.       Default         =   -1  'True
  18.       Height          =   375
  19.       Left            =   5400
  20.       TabIndex        =   6
  21.       Top             =   120
  22.       Width           =   855
  23.    End
  24.    Begin ListBox GroupList 
  25.       Height          =   1200
  26.       Left            =   360
  27.       TabIndex        =   1
  28.       Top             =   2520
  29.       Width           =   4935
  30.    End
  31.    Begin ListBox TrusteePathList 
  32.       FontBold        =   -1  'True
  33.       FontItalic      =   0   'False
  34.       FontName        =   "Courier New"
  35.       FontSize        =   9.75
  36.       FontStrikethru  =   0   'False
  37.       FontUnderline   =   0   'False
  38.       Height          =   1230
  39.       Left            =   360
  40.       TabIndex        =   0
  41.       Top             =   720
  42.       Width           =   4935
  43.    End
  44.    Begin Label DriveLabel 
  45.       Height          =   255
  46.       Left            =   360
  47.       TabIndex        =   7
  48.       Top             =   3960
  49.       Width           =   5055
  50.    End
  51.    Begin Label Label3 
  52.       Caption         =   "Group membership:"
  53.       Height          =   255
  54.       Left            =   120
  55.       TabIndex        =   5
  56.       Top             =   2280
  57.       Width           =   1695
  58.    End
  59.    Begin Label VolumeLabel 
  60.       Height          =   255
  61.       Left            =   120
  62.       TabIndex        =   4
  63.       Top             =   480
  64.       Width           =   4575
  65.    End
  66.    Begin Label UserNameLabel 
  67.       Height          =   255
  68.       Left            =   840
  69.       TabIndex        =   3
  70.       Top             =   120
  71.       Width           =   3375
  72.    End
  73.    Begin Label Label1 
  74.       Caption         =   "User:"
  75.       Height          =   255
  76.       Left            =   120
  77.       TabIndex        =   2
  78.       Top             =   120
  79.       Width           =   495
  80.    End
  81. End
  82.  
  83. Function AttachToServer (serverName$, userName$, password$) As Integer
  84. 'returns connection ID of specified server if already logged in
  85. 'logs in and returns connection ID, if not already logged in
  86. 'returns 0 if unable to log in
  87. 'password and username can be empty if already logged in to
  88. '   specified server
  89.  
  90.     Dim loginTime As DATE_AND_TIME
  91.  
  92.     cCode% = GetConnectionID(serverName$, connectionID%)
  93.     If (cCode% <> SUCCESSFUL) Then
  94.         'either we're not attached, or we're already attached
  95.         If (connectionID% = 0) Then
  96.             'we're not attached
  97.             alreadyAttached% = False
  98.             'Get an attachment to server
  99.             cCode% = AttachToFileServer(serverName$, connectionID%)
  100.             If (cCode% <> SUCCESSFUL) Then
  101.                 AttachToServer = 0
  102.                 Exit Function
  103.             End If
  104.         End If
  105.     End If
  106.  
  107.     'see if we're logged in, or just attached
  108.     SetPreferredConnectionID (connectionID%)
  109.     connNum& = GetConnectionNumber()
  110.     oName$ = String$(48, 0)
  111.     cCode% = GetConnectionInformation(connNum&, oName$, oType%, oID&, loginTime)
  112.  
  113.     If (cCode% = SUCCESSFUL) Then
  114.         'we're logged in
  115.         AttachToServer = connectionID%
  116.         alreadyAttached% = True
  117.  
  118.     Else
  119.         'then log in
  120.         cCode% = LoginToFileServer(userName$, OT_USER, password$)
  121.         If (cCode% <> SUCCESSFUL) Then
  122.             AttachToServer = 0
  123.         Else
  124.             AttachToServer = connectionID%
  125.         End If
  126.         alreadyAttached% = False
  127.     End If
  128. End Function
  129.  
  130. Function DisconnectFromServer (connectionID%) As Integer
  131.     cCode% = DetachFromFileServer(connectionID%)
  132.     If (cCode% = SUCCESSFUL) Then
  133.         DisconnectFromServer = True
  134.     Else
  135.         DisconnectFromServer = False
  136.     End If
  137. End Function
  138.  
  139. Sub DoneButton_Click ()
  140.     End
  141. End Sub
  142.  
  143. Sub Form_Load ()
  144.     'we are assuming that the user has the same username on the default server
  145.     '  and on the server we are attaching to
  146.     connectionID% = AttachToServer(serverName$, userName$, password$)
  147.     If (connectionID% = 0) Then
  148.         MsgBox "Unable to attach to server " + serverName$, MB_OK, "Error"
  149.     Else
  150.         If (MapDriveLetter(connectionID%) <> True) Then
  151.             MsgBox "Unable to map network drive", MB_OK, "Error"
  152.         Else
  153.             DriveLabel.Caption = "Successfully mapped drive to " + serverName$ + "/" + netPath$
  154.         End If
  155.  
  156.         If (GetTrusteeInformation() <> True) Then
  157.             MsgBox "Error getting trustee information", MB_OK, "Error"
  158.         End If
  159.  
  160.         If (GetGroupInformation() <> True) Then
  161.             MsgBox "Error getting group  information", MB_OK, "Error"
  162.         End If
  163.  
  164.         If (Not alreadyAttached%) Then
  165.             If (DisconnectFromServer(connectionID%) <> True) Then
  166.                 MsgBox "Error disconnecting from server " + serverName$, MB_OK, "Error"
  167.             End If
  168.         End If
  169.     End If
  170.  
  171.     'restore preferred connection ID
  172.     SetPreferredConnectionID (originalPreferredServer%)
  173. End Sub
  174.  
  175. Function GetGroupInformation () As Integer
  176.     Dim loginTime As DATE_AND_TIME
  177.     Dim seg As PROPERTY_VALUE
  178.  
  179.     'we already called GetConnectionNumber and GetConnectionInformation
  180.     '  to get the bindery object information in GetTrusteeInformation,
  181.     '  but we'll do it again here, just to keep the two procedures
  182.     '  independent of each other
  183.     connectionNumber& = GetConnectionNumber()
  184.     userName$ = String$(48, 0)
  185.     cCode% = GetConnectionInformation(connectionNumber&, userName$, objectType%, objectID&, loginTime)
  186.     If (cCode% <> SUCCESSFUL) Then
  187.         GetGroupInformation = False
  188.     Else
  189.         segNum% = 1
  190.         Do
  191.             cCode% = ReadPropertyValue(userName$, objectType%, "GROUPS_I'M_IN", segNum%, seg, moreSegs%, flags%)
  192.             i% = 0
  193.             Do
  194.                 'the segment returned by ReadProperty value is an array of up to
  195.                 '  32 longs, each the bindery object ID of a group
  196.                 objectID& = LongSwap(seg.propertyValue(i%))
  197.                 If (objectID& <> 0) Then
  198.                     objectName$ = String$(48, 0)
  199.                     cCode2% = GetBinderyObjectName(objectID&, objectName$, objectType%)
  200.                     If (cCode2% = NO_SUCH_OBJECT) Then
  201.                         GroupList.AddItem "UNKNOWN"
  202.                     ElseIf (cCode2% = SUCCESSFUL) Then
  203.                         GroupList.AddItem objectName$
  204.                     Else
  205.                         MsgBox "Error getting name of group", MB_OK, "Error"
  206.                     End If
  207.                     i% = i% + 1
  208.                 End If
  209.             Loop While ((objectID& <> 0) And (i% < 128))
  210.             segment% = segment% + 1
  211.         Loop While ((cCode% = SUCCESSFUL) And (moreSegs% = 255))
  212.  
  213.         If (moreSegs% = 255) Then
  214.             GetGroupInformation = False
  215.         Else
  216.             GetGroupInformation = True
  217.         End If
  218.     End If
  219. End Function
  220.  
  221. Function GetRights (rightsMask%) As String
  222. 'Returns a string corresponding to the trustee rights for
  223. '   the specified rights mask.  Assumes NetWare v3.x/4.x
  224. '   See NWDIR.BAS for global const declarations for
  225. '   NetWare v2. x rights
  226.  
  227.     If (rightsMask% And TR_READ) Then
  228.         rights$ = "R"
  229.     Else
  230.         rights$ = " "
  231.     End If
  232.  
  233.     If (rightsMask% And TR_WRITE) Then
  234.         rights$ = rights$ + "W"
  235.     Else
  236.         rights$ = rights$ + " "
  237.     End If
  238.  
  239.     If (rightsMask% And TR_CREATE) Then
  240.         rights$ = rights$ + "C"
  241.     Else
  242.         rights$ = rights$ + " "
  243.     End If
  244.     
  245.     If (rightsMask% And TR_ERASE) Then
  246.         rights$ = rights$ + "E"
  247.     Else
  248.         rights$ = rights$ + " "
  249.     End If
  250.  
  251.     'access control
  252.     If (rightsMask% And TR_ACCESS) Then
  253.         rights$ = rights$ + "A"
  254.     Else
  255.         rights$ = rights$ + " "
  256.     End If
  257.  
  258.     'file scan
  259.     If (rightsMask% And TR_FILE) Then
  260.         rights$ = rights$ + "F"
  261.     Else
  262.         rights$ = rights$ + " "
  263.     End If
  264.  
  265.     'modify file attributes
  266.     If (rightsMask% And TR_MODIFY) Then
  267.         rights$ = rights$ + "M"
  268.     Else
  269.         rights$ = rights$ + " "
  270.     End If
  271.  
  272.     If (rightsMask% And TR_SUPERVISOR) Then
  273.         rights$ = rights$ + "S"
  274.     Else
  275.         rights$ = rights$ + " "
  276.     End If
  277.  
  278.     GetRights = rights$
  279. End Function
  280.  
  281. Function GetTrusteeInformation () As Integer
  282.     Dim loginTime As DATE_AND_TIME
  283.  
  284.     connectionNumber& = GetConnectionNumber()
  285.     userName$ = String$(48, 0)
  286.     cCode% = GetConnectionInformation(connectionNumber&, userName$, objectType%, objectID&, loginTime)
  287.     If (cCode% <> SUCCESSFUL) Then
  288.         GetTrusteeInformation = False
  289.     Else
  290.         volume% = 0
  291.         volumeName$ = String$(16, 0)
  292.         cCode% = GetVolumeName(0, volumeName$)
  293.         VolumeLabel.Caption = "Trustee rights for volume " + volumeName$ + ":"
  294.         sequence% = 0
  295.         Do
  296.             trusteePath$ = String$(255, 0)
  297.             cCode% = ScanBinderyObjectTrusteePaths(objectID&, volume%, sequence%, accessMask%, trusteePath$)
  298.             If ((cCode% = SUCCESSFUL) And (Asc(trusteePath$) <> 0)) Then
  299.                 rights$ = GetRights(accessMask%)
  300.                 TrusteePathList.AddItem rights$ + "  " + trusteePath$
  301.             End If
  302.         Loop While ((cCode% = SUCCESSFUL) And (Asc(trusteePath$) <> 0))
  303.  
  304.         If (cCode% <> SUCCESSFUL) Then
  305.             GetTrusteeInformation = False
  306.         Else
  307.             GetTrusteeInformation = True
  308.         End If
  309.     End If
  310. End Function
  311.  
  312. Function MapDriveLetter (connectionID%) As Integer
  313.     'pass a null in driveLetter$ to map next available drive
  314.     driveLetter$ = Chr$(0)
  315.     netPath$ = "SYS:\"
  316.     cCode% = MapDrive(connectionID%, NO_BASE_DRIVE, netPath$, DRIVE_ADD, 0, driveLetter$)
  317.     If (cCode% = SUCCESSFUL) Then
  318.         MapDriveLetter = True
  319.     Else
  320.         MapDriveLetter = False
  321.     End If
  322. End Function
  323.  
  324.